package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.small.util.ResponseResultDTO;
import com.stylefeng.guns.modular.system.model.ArtificerBusiness;
import com.stylefeng.guns.modular.system.model.ArtificerMeans;
import com.stylefeng.guns.modular.system.service.IArtificerBusinessService;
import com.stylefeng.guns.modular.system.service.IArtificerMeansService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 技师经营项目控制器
 *
 * @author fengshuonan
 * @Date 2019-09-09 21:55:01
 */
@Controller
@RequestMapping("/artificerBusiness")
public class ArtificerBusinessController extends BaseController {

    private String PREFIX = "/system/artificerBusiness/";

    @Autowired
    private IArtificerBusinessService artificerBusinessService;

    @Autowired
    private IArtificerMeansService artificerMeansService;
    /**
     * 跳转到技师经营项目首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "artificerBusiness.html";
    }

    /**
     * 跳转到添加技师经营项目
     */
    @RequestMapping("/artificerBusiness_add")
    public String artificerBusinessAdd() {
        return PREFIX + "artificerBusiness_add.html";
    }

    /**
     * 跳转到修改技师经营项目
     */
    @RequestMapping("/artificerBusiness_update/{artificerBusinessId}")
    public String artificerBusinessUpdate(@PathVariable Integer artificerBusinessId, Model model) {
        ArtificerBusiness artificerBusiness = artificerBusinessService.selectById(artificerBusinessId);
        model.addAttribute("item",artificerBusiness);
        LogObjectHolder.me().set(artificerBusiness);
        return PREFIX + "artificerBusiness_edit.html";
    }

    /**
     * 获取技师经营项目列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return artificerBusinessService.selectList(null);
    }

    /**
     * @api {get} /artificerBusiness/add  技师项目新增
     * @apiName  addArtificerBusiness
     * @apiGroup ArtificerBusiness
     *
     * @apiParam {Object} [ArtificerBusiness]  参数对照model属性.
     *
     * @apiSuccessExample {json} Success-Response:
     *      HTTP/1.1 200 OK
     *    {
     * 		"message":"操作成功",
     * 	    "code":"200"
     *    }
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ArtificerBusiness artificerBusiness) {
        artificerBusinessService.insert(artificerBusiness);
        return SUCCESS_TIP;
    }

    /**
     * 删除技师经营项目
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer artificerBusinessId) {
        artificerBusinessService.deleteById(artificerBusinessId);
        return SUCCESS_TIP;
    }

    /**
     * 修改技师经营项目
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ArtificerBusiness artificerBusiness) {
        artificerBusinessService.updateById(artificerBusiness);
        ArtificerMeans artificerMeans=new ArtificerMeans();
        artificerMeans.setId(artificerBusiness.getTypeId());
        artificerMeans.setState(2);
        artificerMeansService.updateById(artificerMeans);
        return SUCCESS_TIP;
    }

    /**
     * 技师经营项目详情
     */
    @RequestMapping(value = "/detail/{artificerBusinessId}")
    @ResponseBody
    public Object detail(@PathVariable("artificerBusinessId") Integer artificerBusinessId) {
        return artificerBusinessService.selectById(artificerBusinessId);
    }

    /**
     * @api {get} /artificerBusiness/search/{id}  技师项目列表
     * @apiName  searchArtificerBusiness
     * @apiGroup ArtificerBusiness
     *
     * @apiParam {Number} id 技师id.
     *
     * @apiSuccessExample {json} Success-Response:
     *      HTTP/1.1 200 OK
     *    {
     *   "data": [
     *    {
     *     "artificerId": 2,
     *    "businessName": "全身精油按摩",
     *     "ced": 0,
     *    "createTime": "",
     *     "describe": "全身血位按摩",
     *    "discount": "",
     *    "id": 3,
     *     "orderNotice": "",
     *    "pointsAttention": "",
     *    "praiseRate": "",
     *    "price": 160,
     *     "remark": "",
     *    "serviceDuration": 120,
     *    "totalCount": ""
     *   }
     *    ],
     *    "msg": "SUCCESS",
     *   "status": "0000",
     *   "userType": ""
     *    }
     */
    @RequestMapping(value = "/search/{id}")
    @ResponseBody
    public ResponseResultDTO list(@PathVariable("id") Integer id) {
        return artificerBusinessService.searchByArtificerId(id);
    }

    @RequestMapping(value = "/getAllBusiness/{id}")
    @ResponseBody
    public ResponseResultDTO getAllBusiness(@PathVariable("id") Integer id) {
        return artificerBusinessService.getAllBusiness(id);
    }

    /**
     * 获取一个项目
     * @param id
     * @return
     */
    @RequestMapping(value = "/getOneBusiness/{id}")
    @ResponseBody
    public ResponseResultDTO getOneBusiness(@PathVariable("id") Integer id) {
        return artificerBusinessService.getOneBusiness(id);
    }
}
